
module jade.tpl.Factory;

import jade.tpl.Template ;


struct Tpl_Factory {
	static const	ClassName	= `Tpl` ;
	
	static Program		program ;
	static string		tpl_boost_source  ;

	static void Init(string boost_file = `tpl.js` ){
		if( program !is null ) {
			return ;
		}
		tpl_boost_source	= cast(string) std.file.read(boost_file)  ;
		program			= new Program ;
		DTpl_Object.Init(program.callcontext.global);
		program.compile(boost_file, assumeUnique( tpl_boost_source ), null) ;
		program.execute(null);
	}
	
	static DTpl_Object Create(string tpl_name, string filename = null ){
		DTpl_Object tpl	= new DTpl_Object(tpl_prototype);
		tpl.tpl_name	= tpl_name.idup ;
		tpl.options.Put("name", tpl.tpl_name, 0 );
		tpl.jade.setTplSourceFile(filename) ;
		return tpl ;
	}
	
}

